package com.h.heal.service.impl;

import com.h.heal.common.SessionParameter;
import com.h.heal.entity.Admin;
import com.h.heal.mapper.AdminMapper;
import com.h.heal.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public String login(Admin admin, HttpSession httpSession) {
        Admin adminNameDB = adminMapper.findByName(admin.getAdmin_name());
        Admin adminDB = adminMapper.findByNameAndPwd(admin.getAdmin_name(), admin.getAdmin_pwd());
        if (adminNameDB == null) {
            return "error_name";
//        } else if(adminDB == null){
//            return "error_pwd";        //那就用这个办法吧。
        }else if(adminDB != null){
            httpSession.setAttribute(SessionParameter.ADMIN_INFO, adminDB);
            return "ok";
        }else {
            return "error_pwd";  //受苦了unknow君
        }
    }
}
